#include "CurtainManager.h"
#include "Protocol/ProtocolApi.h"
#include "CurtainActManager.h"
#include "errorCode.h"
#include "ScreenMirrorStream.h"

CurtainManager::Ptr CurtainManager::Instance(){
    static auto ptr = std::make_shared<CurtainManager>();
    return ptr;
}


CurtainManager::CurtainManager(){
    RegistRPC();
}

CurtainManager::~CurtainManager(){
}

void CurtainManager::RegistRPC(){
    Protocol::IProtocolInterface::GetInstance()->AuditoryworksRegistRequestRpcEx("CloseCurrentLayout", 
    [this](const Json::Value& req_params, Json::Value& res_result, std::string& errinfo, int& errorCode){
        return CloseCurrentLayout(req_params, res_result, errinfo, errorCode);
    });
}


 bool CurtainManager::CloseCurrentLayout(const Json::Value& req_params, Json::Value& res_result, 
    std::string& errinfo, int& errorCode){
    
    ///判定设备当前是否在投屏
    if(Media::ScreenMirrorStream::instance()->getShareScreenStatus())
    {
        errinfo = "The device is displaying screen mirroring information, please try again later.";
        errorCode = Media::ScreenPlaying;
        LOG_PrintError("Close DigitalSignage faild, errinfo=%s\n", errinfo.c_str());
		return false;        
    }

    if(!Media::CurtainActManager::instance()->playDefaultCurtain()){
        errorf("CloseCurrentLayout  curtain faild\n");
        return false;
    }
    return true;
 }